﻿using System;
using System.Diagnostics;
using System.Globalization;

namespace Common.Utilities.TextMatch
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class StringConverterBase : IStringConverter
    {
        /// <summary>
        /// 
        /// </summary>
        protected StringConverterBase() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public object Convert(object value)
        {
            Debug.Assert(value != null, "Unexpected null value.", "The StringConverterBase.Convert(Object) method requires a value.");

            if (value == null)
                throw new ArgumentNullException("value");

            try
            {
                return Convert(System.Convert.ToString(value, CultureInfo.CurrentCulture));
            }
            catch
            {
                throw new ArgumentException(NamespaceUtility.Resource["Error.InvalidArgumentCast", "value", "String"]);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public abstract string Convert(string value);
    }
}
